#include <iostream>
#include <vector>
#include <unistd.h>
#include "block_queue.hpp"
#include "ring_queue.hpp"

BlockQueuePC<int> bq(5); // 阻塞队列
RingQueuePC<int> rq(5); // 环形队列

void* Produce(void* args)
{
    while(1)
    {
        int* id = (int*)args;
        rq.Push(*id);
        std::cout << "thread:" << *id << " Push:" << *id << std::endl;
        sleep(2);
    }

    return nullptr;
}

void* Consume(void* args)
{
    while(1)
    {
        int* id = (int*)args;
        int task;
        rq.Pop(&task);
        std::cout << "thread:" << *id << " Pop:" << task << std::endl;
        sleep(3);
    }

    return nullptr;
}

int main()
{
    std::vector<pthread_t> ProducerId(3);
    std::vector<pthread_t> ConsumerId(2);
    int producer_ids[3] = {1, 2, 3};
    int consumer_ids[2] = {1, 2};
    for(int i = 0; i < 3; i++)
    {
        pthread_create(&ProducerId[i], nullptr, Produce, &producer_ids[i]);
    }
    for(int i = 0; i < 2; i++)
    {
        pthread_create(&ConsumerId[i], nullptr, Consume, &consumer_ids[i]);
    }

    for(int i = 0; i < 3; i++)
    {
        pthread_join(ProducerId[i], nullptr);
    }
    for(int i = 0; i < 2; i++)
    {
        pthread_join(ConsumerId[i], nullptr);
    }

    return 0;
}